Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Save battery thresholds to flash #498

Merged
merged 2 commits into from
Nov 26, 2024
Merged

Save battery thresholds to flash #498

merged 2 commits into from
Nov 26, 2024

Conversation

crawfxrd
Copy link
Member

@crawfxrd crawfxrd commented Aug 22, 2024

Make battery thresholds persistent by saving them in flash space. This allows configuring them after EC reset (system powered-off, unplugged) but before any system firmware or OS policy can be applied.

As part of this, the dynamic keymap is moved from the hard-coded address of 0x1FC00 to "the last sector"; Models with 256 KiB flash (CONFIG_EC_FLASH_SIZE_256K=y) will lose their layout and need to reconfigure it.

Test

  • When not configured, default values (90, 100) are used across multiple EC resets
  • When configured, the profile/custom values are used across multiple EC resets
    • If flash is dumped, the values are present in the ROM image

Check values with:

  • system76-power charge-thresholds
  • cat /sys/class/power_supply/BAT0/charge_control_{start,end}_threshold

With the use of 256 KiB flash chips, the hard-coded address of 0x1FC00
may no longer be "the last sector".

Signed-off-by: Tim Crawford <[email protected]>
jackpot51
jackpot51 previously approved these changes Nov 22, 2024
@crawfxrd
Copy link
Member Author

crawfxrd commented Nov 25, 2024

Writing to flash works.

0003f800: 54 42 56 5a ff ff ff ff ff ff ff ff ff ff ff ff  TBVZ............

Reading it back does not.

$ cat /sys/class/power_supply/BAT0/charge_control_{start,end}_threshold
1
1

And I don't know why. And now that I've said it, it's very obvious.

Make battery thresholds persistent by saving them in flash space. This
allows configuring them after EC reset (system powered-off, unplugged)
but before any system firmware or OS policy can be applied.

Signed-off-by: Tim Crawford <[email protected]>
@crawfxrd crawfxrd marked this pull request as ready for review November 25, 2024 23:22
@crawfxrd crawfxrd requested review from jackpot51 and a team November 25, 2024 23:23
@leviport leviport self-assigned this Nov 26, 2024
Copy link
Member

@leviport leviport left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Tested on darp10-b, and this seems to be working great. The thresholds I set persist through multiple EC resets. Very nice!

@crawfxrd crawfxrd merged commit 85da2d2 into master Nov 26, 2024
48 checks passed
@crawfxrd crawfxrd deleted the save-bct branch November 26, 2024 22:17
@crawfxrd crawfxrd linked an issue Dec 13, 2024 that may be closed by this pull request
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Charging thresholds don't persist through an EC reset
3 participants